﻿#ifndef PROBUTILITY_H
#define PROBUTILITY_H

#include "systemparamdef.h"

class Probutility
{
public:
    Probutility();

    //创建文件夹
    static bool CreateDirectory(const QString sPath)
    {
        QDir fileDir;
        //创建系统文件夹
        if(!fileDir.exists(sPath))
        {
            bool bflag = fileDir.mkpath(sPath);
            if(!bflag)
            {
                return false;
            }
        }
        return true;
    }

    //创建文件
    static bool CreateFile(const QString sFileName,const QString sHeaderType = "Systems")
    {
        QFile file(sFileName);
        //创建文件
        if(!file.exists(sFileName))
        {
            if(!file.open(QIODevice::ReadWrite))
            {
                return false;
            }
            QDomDocument doc;
            QDomProcessingInstruction instruction;
            instruction=doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"utf-8\"");
            doc.appendChild(instruction);

            //添加根节点
            QDomElement root=doc.createElement(sHeaderType);
            doc.appendChild(root);
            QTextStream out_stream(&file);
            doc.save(out_stream,4); //缩进4格
            file.close();
        }
        return true;
    }

    static QString GetSystemType(eSystemType type)
    {
        QString sMsgType = "";
        switch (type)
        {
        case Server:
            sMsgType = "服务器";
            break;
        case Client:
            sMsgType = "客户端";
            break;
        }
        return sMsgType;
    }

    //获取数据类型（int .....）
    static QString GetDataInfoType(const PROTOCOLDATATYPE nTypeId)
    {
        switch (nTypeId)
        {
        case T_BOOL:
            return "bool";
        case T_CHAR:
            return "char";
        case T_UCHAR:
            return "unsinged char";
        case T_SHORT:
            return "short";
        case T_USHORT:
            return "unsinged short";
        case T_INT:
            return "int";
        case T_UINT:
            return "unsinged int";
        case T_INT64:
            return "int64";
        case T_UINT64:
            return "unsinged int64";
        case T_FLOAT:
            return "float";
        case T_DOUBLE:
            return "double";
        case T_STRUCT:
            return "struct";
        case T_UNION:
            return "union";
        case T_STRING:
            return "string";
        case T_ARRAY:
            return "array";
        }
        return "";
    }

};

#endif // PROBUTILITY_H
